package com.qfjy.homework.limingwei.dynamic;

import java.lang.reflect.Proxy;

/**
 * @author : LIMINGWEI
 * @version : 1.0
 * @date : 11/10/22 7:44 PM
 */
public class DynamicProxyUtils {
    //目标代理对象
    private Object target;

    public DynamicProxyUtils(Object target) {
        this.target = target;
    }
    public Object getProxy(){
        Object instance = Proxy.newProxyInstance(
                target.getClass().getClassLoader(),
                target.getClass().getInterfaces(),
                (proxy, method, args) -> {
                    System.out.println("开启代理");
                    Object invoke = method.invoke(target, args);
                    System.out.println("结束代理");
                    return invoke;
                }

        );
        return instance;
    }
}
